package com.gimi.cloud.bbp.manage.consumer.service.page.impl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.exception.MsgException;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.page.PageColumnDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.page.PageColumnFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.page.PageColumnService;

@Service
public class PageColumnServiceImpl implements PageColumnService{
	
	@Autowired private PageColumnFeignService pageColumnFeignService;
	
	@Override
	public Response savePageColumn(String requestBody, HttpServletRequest request, HttpServletResponse response) {
		PageColumnDTO dto = JSON.toJavaObject(JSON.parseObject(requestBody), PageColumnDTO.class);
		return pageColumnFeignService.savePageColumn(dto);
	}

	@Override
	public Response delPageColumnAllById(String requestBody, HttpServletRequest request, HttpServletResponse response) {
		PageColumnDTO dto = JSON.toJavaObject(JSON.parseObject(requestBody), PageColumnDTO.class);
		if (dto.getId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		return pageColumnFeignService.delPageColumnAllById(dto);
	}

	@Override
	public Response getPageColumnById(String requestBody, HttpServletRequest request, HttpServletResponse response) {
		PageColumnDTO dto = JSON.toJavaObject(JSON.parseObject(requestBody), PageColumnDTO.class);
		if (dto.getId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		return pageColumnFeignService.getPageColumnById(dto);
	}

	@Override
	public Response addPageColumnByTemplateId(String requestBody, HttpServletRequest request,
			HttpServletResponse response) {
		PageColumnDTO dto = JSON.toJavaObject(JSON.parseObject(requestBody), PageColumnDTO.class);
		if (dto.getPageTemplateId() == null || dto.getPageTemplateId() == null) {
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR);
		}
		return pageColumnFeignService.addPageColumnByTemplateId(dto);
	}


}
